package com.cskaoyan.controller.wxorder;

import com.cskaoyan.bean.BasePageInfo;
import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.CommonData;
import com.cskaoyan.bean.MemoryBean;
import com.cskaoyan.exception.MarketValidationException;
import com.cskaoyan.service.wxorder.WxFootprintService;
import com.cskaoyan.util.common.Constant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author Zhang Tao
 * @version 1.0.0
 * @description
 * @date since 2022-07-19 21:03
 */
@RestController
@RequestMapping("wx/footprint")
public class WxFootprintController {
    @Autowired
    WxFootprintService wxFootprintService;
    @Autowired
    MemoryBean memoryBean;
    @GetMapping("list")
    public BaseRespVo foorprintList(@RequestHeader(Constant.WX_TOKEN_HEADER) String token,
                                        BasePageInfo basePageInfo) throws MarketValidationException {
        Integer id = memoryBean.tokenAndUserId.get(token);
        if(id==null){
            throw new MarketValidationException("请重新登陆！");
        }
        CommonData footprint = null;
        footprint = wxFootprintService.queryFootprint(basePageInfo,id);
        return BaseRespVo.ok(footprint);

    }
    @PostMapping("delete")
    public BaseRespVo footprintDelete(@RequestBody Map map){
        Integer id = (Integer) map.get("id");
      wxFootprintService.deleteFootprint(id);
      return BaseRespVo.ok();
    }
}
